<?php 
class Zen_Behavior_Morphy extends Zen_Behavior_Model {
	
	private $_morphy_params = array();
	private $_field_source = null;
	private $_field_store = null;
	
	public function __construct($field_source, $field_store, $morphy_params) {
		$this->_morphy_params = $morphy_params;
		$this->_field_store = $field_store;
		$this->_field_source = $field_source;
	}
	
	public function beforeCreate($params){
		$params = $this->_prepareCreateUpdate($params);
		return $params;
	}
	
	public function beforeUpdate($params){
		$params = $this->_prepareCreateUpdate($params);
		return $params;
	}
	
	private function _prepareCreateUpdate($params){
		$field_store = $this->_field_store ;
		$field_source = $this->_field_source ;
		if (! isset($params[$field_source]) ) return $params;
		if (! $params[$field_source] ) return $params;
		if (! isset($params[$field_store]) ) return $params;
		if ( $params[$field_store]) return $params;
		$model = new Morphy_Model_Word();
		$morphy_params = $this->_morphy_params ;
		$params[$field_store] = $model->get($params[$field_source], $morphy_params);
		return $params;
	}
	
}